package com.example.thread2.thread4;

import lombok.SneakyThrows;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static cn.hutool.core.lang.Console.print;


public class DaemonFromFactory implements  Runnable{

    @SneakyThrows
    @Override
    public void run() {
        while(true){
            TimeUnit.MILLISECONDS.sleep(100);
            print(Thread.currentThread() + " " + this);
        }
    }
    public static void main(String[] args) throws Exception{
        ExecutorService exec = Executors.newCachedThreadPool(new DaemonThreadFactory());
        for(int i=0; i<10; i++){
            exec.execute(new DaemonFromFactory());
        }
        print("All daemons started");
        TimeUnit.MILLISECONDS.sleep(500);
    }
}
